package com.ruoyi.web.controller.example;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Anonymous
@RestController
public class BindController extends BaseController {

    @RequestMapping("/getUserId")
    public void getUserId(HttpServletRequest request){
        //获取请求中，参数为userId的数据
        //在浏览器输入http://localhost:8080/getUserId?userId=111111
        String userId = request.getParameter("userId");
        String name = request.getParameter("name");
        System.out.println("用户的id是：" + userId);

    }

    @GetMapping("/getUserName")
    public String getUserName(@RequestParam(value = "name",required = true,
    defaultValue = "默认的名字-董虹妤") String username){
        System.out.println("用户名称是：" + username);
        return username;
    }
    //localhost:8080/getUserName?name=董虹妤2619
    //localhost:8080/getUserName2/dhy
    @GetMapping("getUserName2/{name}")
    public String getUserName2(@PathVariable(
            value = "name")String username) {
        return "获取到的用户名称是：" + username;
    }
}
